<%--
  Created by IntelliJ IDEA.
  User: BluceYoung
  Date: 2020/12/3
  Time: 15:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="temp/login_head.jsp"></jsp:include>
<form id="regForm" action="${pageContext.request.contextPath}/login.html" method="post">
    <h1>用户登录</h1>
    <div>
        <input type="text" name="loginMail" value="wuban@qq.com" class="form-control" placeholder="注册邮箱" required=""/>
    </div>
    <div>
        <input type="password" name="pwd" value="123456" maxlength="20" class="form-control" placeholder="密码 6-20位" required=""/>
    </div>
    <div>
        <button type="submit" class="btn btn-default">登录</button>
        <a  class="btn btn-default" href="${pageContext.request.contextPath}/register.html">去注册</a>
        <a class="reset_pass" href="#">忘记密码?</a>
    </div>
    <div class="clearfix"></div>
    <div class="separator">
        <p class="change_link">New to site?
            <a href="#signup" class="to_register"> Create Account </a>
        </p>
        <div class="clearfix"></div>
        <br/>
        <div>
            <h1><i class="fa fa-paw"></i> Gentelella Alela!</h1>
            <p>©2016 All Rights Reserved. Gentelella Alela! is a Bootstrap 3 template. Privacy and Terms</p>
        </div>
    </div>
</form>
<jsp:include page="temp/login_foot.jsp"></jsp:include>
<script type="text/javascript">
    var msg="${msg}";
    if(msg.length>0){
        if(msg.indexOf("需激活")>=0){
            active();
        }else{
            alert(msg)
        }
    }
    function active(){
        var code = prompt("请输入激活验证码：","");
        if(code!=null){//点了取消才是null
            //发送ajax请求激活
            var userId = msg.split("|")[1];
            $.ajax({
                url:"${pageContext.request.contextPath}/active",
                data:"userId="+userId+"&code="+code,
                type:"get",
                async: false,
                dataType:"text",
                success:function(result){
                    alert(result);
                    if(result.indexOf("成功")>=0){
                        window.location="${pageContext.request.contextPath}/login.html";
                    }else{//要么验证码输错，要么过期
                        active();
                    }
                }
            });
        }
    }
</script>
